package com.zjsd.sqeybusiness.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zjsd.sqeybusiness.domain.AgencyInfo;
import com.zjsd.sqeybusiness.service.IAgencyInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代理商信息Controller
 *
 * @author Zheng
 * @date 2020-11-05
 */
@RestController
@RequestMapping("/jph/agencyInfo")
public class AgencyInfoController extends BaseController
{
    @Autowired
    private IAgencyInfoService agencyInfoService;

    /**
     * 查询代理商信息列表
     */
    @PreAuthorize("@ss.hasPermi('jph:agencyInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(AgencyInfo agencyInfo)
    {
        startPage();
        List<AgencyInfo> list = agencyInfoService.selectAgencyInfoList(agencyInfo);
        return getDataTable(list);
    }

    /**
     * 导出代理商信息列表
     */
    @PreAuthorize("@ss.hasPermi('jph:agencyInfo:export')")
    //@Log(title = "代理商信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AgencyInfo agencyInfo)
    {
        List<AgencyInfo> list = agencyInfoService.selectAgencyInfoList(agencyInfo);
        ExcelUtil<AgencyInfo> util = new ExcelUtil<AgencyInfo>(AgencyInfo.class);
        return util.exportExcel(list, "agencyInfo");
    }

    /**
     * 获取代理商信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('jph:agencyInfo:query')")
    @GetMapping(value = "/{agencyId}")
    public AjaxResult getInfo(@PathVariable("agencyId") Long agencyId)
    {
        return AjaxResult.success(agencyInfoService.selectAgencyInfoById(agencyId));
    }

    /**
     * 新增代理商信息
     */
    @PreAuthorize("@ss.hasPermi('jph:agencyInfo:add')")
    //@Log(title = "代理商信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgencyInfo agencyInfo)
    {
        return toAjax(agencyInfoService.insertAgencyInfo(agencyInfo));
    }

    /**
     * 修改代理商信息
     */
    @PreAuthorize("@ss.hasPermi('jph:agencyInfo:edit')")
    //@Log(title = "代理商信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgencyInfo agencyInfo)
    {
        return toAjax(agencyInfoService.updateAgencyInfo(agencyInfo));
    }

    /**
     * 删除代理商信息
     */
    @PreAuthorize("@ss.hasPermi('jph:agencyInfo:remove')")
    //@Log(title = "代理商信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{agencyIds}")
    public AjaxResult remove(@PathVariable Long[] agencyIds)
    {
        return toAjax(agencyInfoService.deleteAgencyInfoByIds(agencyIds));
    }
}
